﻿<Window x:Class="WTwitter.View.OptionDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:opt="clr-namespace:WTwitter.Model.UserData"
	xmlns:view="clr-namespace:WTwitter.View"
	Name="thisWindow"
    Title="オプション設定" Width="500" Height="500" Loaded="Window_Loaded">
	<!--設定ダイアログ-->
	
	<Window.BindingGroup>
		<BindingGroup Name="OptionBinding"/>
	</Window.BindingGroup>

	<Window.Resources>
				
		<!--全体に適用するStyle-->
		<Style x:Key="{x:Type TextBlock}" TargetType="{x:Type TextBlock}">
			<Setter Property="VerticalAlignment" Value="Center"/>
			<Setter Property="Margin" Value="3,0"/>
		</Style>
		<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">
			<Setter Property="VerticalAlignment" Value="Center"/>
			<Setter Property="Margin" Value="3,0"/>
		</Style>
		<Style x:Key="OneEntryStyle" TargetType="{x:Type StackPanel}">
			<Setter Property="Margin" Value="0,3,8,3"/>
			<Setter Property="Orientation" Value="Horizontal"/>
			<Setter Property="VerticalAlignment" Value="Stretch"/>
		</Style>
		
		
		<Style x:Key="TimelineSettingItemContainer" TargetType="{x:Type ListBoxItem}">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ListBoxItem}">
						<GroupBox x:Name="ItemContainer" Header="{Binding Path=TimelineTypeName}" Padding="5">
							<ContentPresenter/>
						</GroupBox>
						<ControlTemplate.Triggers>
							<!--選択アイテムのエフェクト-->
							<Trigger Property="IsSelected" Value="True">
								<Setter TargetName="ItemContainer" Property="BorderThickness" Value="3"/>
								<Setter TargetName="ItemContainer" Property="BorderBrush" Value="DarkGray"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		
		<!--タイムライン用のテンプレート-->
		<DataTemplate DataType="{x:Type opt:TimelineSetting}">
			<StackPanel Orientation="Vertical" Margin="2">
				<WrapPanel VerticalAlignment="Stretch">
					<StackPanel Style="{StaticResource OneEntryStyle}">
						<TextBlock>表示名</TextBlock>
						<TextBox Name="Title" Text="{Binding Path=Name, BindingGroupName=OptionBinding}" MinWidth="70"/>
					</StackPanel>
					<StackPanel Style="{StaticResource OneEntryStyle}">
						<TextBlock>更新間隔</TextBlock>
						<TextBox Text="{Binding Path=UpdateInterval, BindingGroupName=OptionBinding}" Width="30"/>
						<TextBlock>分</TextBlock>
					</StackPanel>
					<StackPanel Style="{StaticResource OneEntryStyle}">
						<TextBlock>起動時読込数</TextBlock>
						<TextBox Text="{Binding Path=StartupReadCount, BindingGroupName=OptionBinding}"></TextBox>
					</StackPanel>
					<CheckBox Content="認証が必要" IsChecked="{Binding Path=IsAuthRequired, BindingGroupName=OptionBinding}" Margin="4,0" VerticalAlignment="Center"/>
				</WrapPanel>
				<DockPanel>
					<TextBlock DockPanel.Dock="Left">URL</TextBlock>
					<TextBox Text="{Binding Path=Url, BindingGroupName=OptionBinding}"/>
				</DockPanel>
			</StackPanel>
		</DataTemplate>

		<DataTemplate DataType="{x:Type opt:DirectMessageSetting}">
			<StackPanel Orientation="Vertical" Margin="2">
				<WrapPanel VerticalAlignment="Stretch">
					<StackPanel Style="{StaticResource OneEntryStyle}">
						<TextBlock>表示名</TextBlock>
						<TextBox Text="{Binding Path=Name, BindingGroupName=OptionBinding}" MinWidth="70"/>
					</StackPanel>
					<StackPanel Style="{StaticResource OneEntryStyle}">
						<TextBlock>更新間隔</TextBlock>
						<TextBox Text="{Binding Path=UpdateInterval, BindingGroupName=OptionBinding}" Width="30"/>
						<TextBlock>分</TextBlock>
					</StackPanel>
					<StackPanel Style="{StaticResource OneEntryStyle}">
						<TextBlock>起動時読込数</TextBlock>
						<TextBox Text="{Binding Path=StartupReadCount, BindingGroupName=OptionBinding}"></TextBox>
					</StackPanel>
					<CheckBox Content="認証が必要" IsChecked="{Binding Path=IsAuthRequired, BindingGroupName=OptionBinding}" Margin="4,0" VerticalAlignment="Center"/>
				</WrapPanel>
				<DockPanel>
					<TextBlock DockPanel.Dock="Left">URL</TextBlock>
					<TextBox Text="{Binding Path=Url, BindingGroupName=OptionBinding}"/>
				</DockPanel>
			</StackPanel>
		</DataTemplate>

		<DataTemplate DataType="{x:Type opt:SearchTimelineSetting}">
			<StackPanel Orientation="Vertical">
				<WrapPanel VerticalAlignment="Stretch">
					<StackPanel Style="{StaticResource OneEntryStyle}">
						<TextBlock>表示名</TextBlock>
						<TextBox Text="{Binding Path=Name, BindingGroupName=OptionBinding}" MinWidth="70"/>
					</StackPanel>
					<StackPanel Style="{StaticResource OneEntryStyle}">
						<TextBlock>更新間隔</TextBlock>
						<TextBox Text="{Binding Path=UpdateInterval, BindingGroupName=OptionBinding}" Width="30"/>
						<TextBlock>分</TextBlock>
					</StackPanel>
					<CheckBox Content="日本語のみ対象" IsChecked="{Binding Path=IsJapaneseOnly, BindingGroupName=OptionBinding}" VerticalAlignment="Center"/>
				</WrapPanel>
				<DockPanel>
					<TextBlock DockPanel.Dock="Left">検索ワード</TextBlock>
					<TextBox Text="{Binding Path=SearchText, BindingGroupName=OptionBinding}"/>
				</DockPanel>
			</StackPanel>
		</DataTemplate>
	</Window.Resources>
	
	<DockPanel>
		<!--下部のパネル-->
		<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Right">
			<Button IsCancel="True" Click="CancelButton_Click"
					HorizontalAlignment="Right">_Cancel</Button>
			<Button IsDefault="True" Click="OkButton_Click"
				HorizontalAlignment="Right">_OK</Button>
		</StackPanel>
		
		<!--上側の本体-->
		<TabControl>
			<TabItem Header="ID">
				<DockPanel>
					<CheckBox Name="IsOAuth" IsChecked="{Binding Path=UserInfo.IsUseOAuth}"
							  DockPanel.Dock="Top">OAuth認証を使う</CheckBox>
					<GroupBox Header="Basic認証" DockPanel.Dock="Top">
						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="Auto"/>
								<ColumnDefinition Width="Auto"/>
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto"/>
								<RowDefinition Height="Auto"/>
							</Grid.RowDefinitions>
							<TextBlock Text="UserName" Grid.Row="0" Grid.Column="0"/>
							<TextBox Grid.Row="0" Text="{Binding Path=UserInfo.UserName}"
									 Grid.Column="1" Width="100"/>
							
							<TextBlock Text="Password" Grid.Row="1" Grid.Column="0"/>
							<PasswordBox Name="PasswordBox" PasswordChar="★"
										 Grid.Row="1" Grid.Column="1" Width="100"/>
						</Grid>
					</GroupBox>
					<GroupBox Header="OAuth認証" DockPanel.Dock="Top">
						<DockPanel>
							<TextBlock DockPanel.Dock="Top">
								1.この
								<Hyperlink Command="{Binding Path=ShowOAuthURLCommand}">リンク</Hyperlink>
								をクリックして許可してください
							</TextBlock>
							<TextBlock DockPanel.Dock="Top" TextWrapping="Wrap">
								2.表示された文字列・数字を以下のテキストボックスに入力して、取得ボタンを押してください
							</TextBlock>
							<TextBox Name="Verifier" DockPanel.Dock="Top"/>
							<Button Command="{Binding Path=GetAccessTokenCommand}" CommandParameter="{Binding ElementName=Verifier, Path=Text}">取得</Button>
						</DockPanel>
					</GroupBox>
					<GroupBox Header="アカウント情報">
						<DockPanel>
							<TextBlock DockPanel.Dock="Top" TextWrapping="Wrap">
								※ID、パスワード等を変更した際は、いったんOKボタンでオプションダイアログを閉じないと反映されません。</TextBlock>
							<Button Command="{Binding Path=ShowAuthInfoCommand}">アカウント情報確認</Button>
						</DockPanel>
					</GroupBox>
				</DockPanel>
			</TabItem>
			
			<TabItem Header="Timeline">
				<DockPanel>
					<WrapPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
						<GroupBox Header="新規追加">
							<StackPanel Orientation="Horizontal">
								<ComboBox x:Name="_timelineTemplates" ItemsSource="{Binding Path=TimelineSettingTemplates}"
										   MinWidth="150">
									<ComboBox.ItemTemplate>
										<DataTemplate>
											<TextBlock Text="{Binding Path=DisplayName}" ToolTip="{Binding Path=Description}"/>
										</DataTemplate> 
									</ComboBox.ItemTemplate>
								</ComboBox>
								<Button Command="{Binding Path=AddTimelineCommand}" CommandParameter="{Binding ElementName=_timelineTemplates, Path=SelectedItem}">追加</Button>
							</StackPanel>
						</GroupBox>
						<GroupBox Header="選択タイムラインを編集">
							<WrapPanel Orientation="Horizontal">
								<Button Command="{Binding Path=UpTimelineOrderCommand}"
										CommandParameter="{Binding ElementName=timelines, Path=SelectedItem}">↑</Button>
								<Button Command="{Binding Path=DownTimelineOrderCommand}"
										CommandParameter="{Binding ElementName=timelines, Path=SelectedItem}">↓</Button>
								<Button Command="{Binding Path=RemoveTimelineCommand}"
									CommandParameter="{Binding ElementName=timelines, Path=SelectedItem}">削除</Button>
							</WrapPanel>
						</GroupBox>
					</WrapPanel>
					<TextBlock DockPanel.Dock="Top">※タイムラインを選択するには、タイトルのあたりをクリックしてください</TextBlock>
					<ListBox x:Name="timelines" ItemsSource="{Binding Path=TimelineSettings}"
							 ItemContainerStyle="{StaticResource TimelineSettingItemContainer}"
							 IsSynchronizedWithCurrentItem="True"
							 HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
					</ListBox>
				</DockPanel>
			</TabItem>
			
			<TabItem Header="短縮URL">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="Auto"/>
						<ColumnDefinition/>
					</Grid.ColumnDefinitions>
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
						<RowDefinition Height="Auto"/>
					</Grid.RowDefinitions>
					<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
						<Hyperlink Command="{Binding Path=ShowBitlyURLCommand}">Bit.ly</Hyperlink>にSign Upしたあと、以下の情報を入力してください
					</TextBlock>
					<TextBlock Grid.Row="1" Grid.Column="0">LoginName</TextBlock>
					<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=Bitly.LoginName}"/>
					<TextBlock Grid.Row="2" Grid.Column="0">API key</TextBlock>
					<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=Bitly.APIKey}"/>
					<TextBlock Grid.Row="3" Grid.Column="0">Version</TextBlock>
					<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=Bitly.Version}"/>
				</Grid>
			</TabItem>
			
			<TabItem Header="表示">
				<StackPanel>
					<StackPanel Orientation="Horizontal">
						<TextBlock>スキン</TextBlock>
						<ComboBox ItemsSource="{Binding Path=Skins}" SelectedItem="{Binding Path=Skin}"/>
					</StackPanel>
					<TextBlock>※スキンを有効にするには本ソフトウェアを再起動してください</TextBlock>
				</StackPanel>
			</TabItem>
			
			<TabItem Header="バージョン情報">
				<view:AboutView/>
			</TabItem>
		</TabControl>
	</DockPanel>
</Window>
